package asserts

import "fmt"

func IsTrue(expression bool, tipCause ITipCause, params ...interface{}) {
	if !expression {
		panic(NewBussinessError(tipCause, params))
	}
}

type ITipCause interface {
	TipCode() int32     //提示码
	TipMessage() string //提示信息
}

type BussinessError struct {
	tipCause ITipCause
	params   []interface{}
	message  string
}

func NewBussinessError(tipCause ITipCause, params []interface{}) *BussinessError {
	message := tipCause.TipMessage() + " " + fmt.Sprint(params)
	err := BussinessError{}
	err.tipCause = tipCause
	err.params = params
	err.message = message
	return &err
}

func (e *BussinessError) Error() string {
	return e.message
}

func (e *BussinessError) Code() int32 {
	return e.tipCause.TipCode()
}
